/*
 * TCPChannel.h
 *
 *  Created on: Sep 11, 2017
 *      Author: zjf
 */

#ifndef SRC_TCPSERVERCHANNEL_H_
#define SRC_TCPSERVERCHANNEL_H_

#include <Poco/Task.h>
#include <Poco/AutoPtr.h>
#include <Poco/NotificationQueue.h>
#include "CustomNotification.h"
#include "TCPServerPacketReaderWriter.h"
#include "TCPServerPacketParams.h"
#include "TCPServerPacket.h"

using namespace Poco;
using namespace utils;

namespace network
{

class TCPServerChannel : public Task
{
public:
	using TPacketParams = TCPServerPacketParams<TCPServerDispatcherPacket, TCPServerPacketReaderWriter>;
	typedef AutoPtr<TCPServerChannel> Ptr;

	TCPServerChannel(std::string& name, UInt32 id, std::function<void(const TCPServerDispatcherPacket::Ptr&)> handlePacket);
	virtual ~TCPServerChannel();

	void runTask();

	void enquenceNotification(CustomNotification<TPacketParams>* pNotif);
private:
	NotificationQueue _nq;
	std::string _name;
	UInt32 _nChannelID;
	std::function<void(const TCPServerDispatcherPacket::Ptr&)> _handlePacket;
};

} /* namespace network */

#endif /* SRC_TCPSERVERCHANNEL_H_ */
